<template>
	<view class="center" v-if="show">
		<wm-poster :imgSrc="poster.imgSrc" :QrSrc="poster.QrSrc" :Title="poster.Title" :PriceTxt="poster.PriceTxt"
		 :OriginalTxt="poster.OriginalTxt" :CanvasBg="poster.CanvasBg" :Name="poster.Name" v-on:success="success">
		</wm-poster>
		<u-button v-if="showbtn" type="success" size="medium" :plain="true" @click="save">保存到相册</u-button>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	var _this;
	import wmPoster from "@/components/wm-poster/wm-poster.vue"
	export default {
		components: {
			wmPoster
		},
		data() {
				return {
					poster: {
						imgSrc: '',
						QrSrc: '',
						Name: '',
						Title: "",
						CanvasBg: ''
					},
				tempFilePath:'',
				showbtn:false,
				show:false,
				
			}
		},
		onLoad(option) {
			_this = this;
			 console.log(option);
			 let poster = JSON.parse(decodeURIComponent(option.poster));
			 _this.setData({
				 poster
			 })
			 _this.show = true;
			 console.log(_this.poster);
		},
		methods: {
			success(res) {
				_this.$refs.uToast.show({
					title: `加载成功`,
					type: 'success'
				})
				_this.tempFilePath = res.tempFilePath
				_this.showbtn = true
			},
			save(){
				if (_this.tempFilePath == '') {
					_this.$refs.uToast.show({
						title: `请重试！`,
						type: 'error'
					})
					return;
				}
				//#ifdef H5
					_this.$refs.uToast.show({
						title: `长按保存！`,
						type: 'error'
					})
					return
				// #endif
				
				
				uni.saveImageToPhotosAlbum({
					filePath: _this.tempFilePath,
					success: function () {
						_this.$refs.uToast.show({
							title: `保存成功！`,
							type: 'success'
						})
						console.log('保存成功');
					}
				});
			},
		}
	}
</script>

<style>
	.center{
		text-align:center;
		overflow: hidden;
	}
</style>
